import { createRouter, createWebHistory } from 'vue-router'
import { createRouterGuards } from './routerGuards'
import Layout from '@/layouts/Layout.vue'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'index',
      redirect: '/chat/new',
      component: Layout,
      children: [
        {
          path: '/chat',
          name: 'chat',
          redirect: '/chat/new',
        },
        {
          path: '/chat/:id',
          name: 'dialogue',
          component: () => import('@/views/pages/chat/dialogue.vue'),
        },
        {
          path: '/plan',
          name: 'plan',
          component: () => import('@/views/pages/menus/plan.vue'),
          meta: {
            title: '套餐订阅',
          },
        },
        {
          path: '/invite',
          name: 'invite',
          component: () => import('@/views/pages/menus/invite.vue'),
          meta: {
            title: '推广返礼',
          },
        },
        {
          path: '/openapi',
          name: 'openapi',
          component: () => import('@/views/pages/menus/openapi.vue'),
          meta: {
            title: '开放API',
          },
        },
      ],
    },
    {
      path: '/wxlogin',
      name: 'wxlogin',
      component: () => import('@/views/pages/user/wxlogin.vue'),
      meta: {
        title: '微信登录',
      },
    },
    {
      path: '/alipay',
      name: 'alipay',
      component: () => import('@/views/pages/user/alipay.vue'),
      meta: {
        title: '支付宝支付',
      },
    },
  ],
})

export function setupRouter(app) {
  app.use(router)
  // 创建路由守卫
  createRouterGuards(router)
}

export default router
